package com.allwees.bs.module.mms.req.register;

import com.allwees.bs.core.modelbase.req.SignedReq;
import com.allwees.bs.core.modelbase.validate.ValidateItem;
import com.allwees.bs.module.mms.entity.RetailerApply;
import com.allwees.core.common.constant.EPlatform;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

@Data
@EqualsAndHashCode(callSuper = true)
public class RetailerRegisterBaseReq extends SignedReq {

    private EPlatform platform;

    private String uuid;

    private String storeName;

    private String firstName;

    private String lastName;

    private String workCountry;

    private String workProvince;

    private String workCity;

    private String workArea;

    private String workAddress;

    private String zipCode;

    private String categoryNo;

    @Override
    protected Object[] signValues() {
        return new Object[]{platform.name(), uuid, storeName, lastName, time.getTime()};
    }

    @Override
    protected String signSeparator() {
        return platform.isApp() ? "_AS_" : "_PC_";
    }

    @Override
    public ValidateItem[] getValidateItems() {
        return new ValidateItem[]{
                ValidateItem.of(StringUtils.isEmpty(uuid), "uuid 不能为空"),
                ValidateItem.of(StringUtils.isEmpty(storeName), "店铺名称不能为空"),
                //ValidateItem.of(StringUtils.isEmpty(firstName), "名字不能为空"),
                ValidateItem.of(StringUtils.isEmpty(lastName), "姓名不能为空"),
                ValidateItem.of(StringUtils.isEmpty(zipCode), "邮编不能为空"),
                ValidateItem.of(StringUtils.isEmpty(categoryNo), "类目不能为空"),
        };
    }

    public RetailerApply toEntity(){
        RetailerApply apply = new RetailerApply();
        BeanUtils.copyProperties(this,apply);
        return apply;
    }

    public String getUsername(){
        return lastName;
    }
}
